<!-- 采购申请 -->
<template>
  <div>
    <el-card style="width: 98%; margin: 0 auto; margin-top: 10px">
      <div class="top">
        <div class="left">
          <div class="box">
            <div class="text">创建时间:</div>
            <div class="rgt">{{ dayjs(purchaseData?.addTime).format("YYYY-MM-DD") }}</div>
          </div>
          <div class="box">
            <div class="text">申请人:</div>
            <div class="rgt">{{ purchaseData?.addAccountName }}</div>
          </div>
          <div class="box">
            <div class="text">品种数:</div>
            <div class="rgt">{{ purchaseData?.counts }}</div>
          </div>
          <div class="box">
            <div class="text">实际采购成本:</div>
            <div class="rgt">{{ purchaseData?.addAccountId }}</div>
          </div>
        </div>
        <div class="deliver">{{ purchaseData?.state }}</div>
      </div>

      <el-table :data="TableData" style="width: 100%">
        <el-table-column prop="id" label="序号" />
        <el-table-column prop="name" label="物料名称" />
        <el-table-column prop="unit" label="单位" />
        <el-table-column prop="supplierName" label="供应商" />
        <el-table-column prop="wholePrice" label="批发价" />
        <el-table-column prop="sellPrice" label="零售价" />
        <el-table-column prop="purchasePrice" label="采购价" />
        <el-table-column prop="purchaseCounts" label="采购数量" />
        <el-table-column prop="receiveCounts" label="采购实际数量" />
      </el-table>

      <div class="end">
        <div class="txt">到货凭证</div>
        <img :src="imgUrl + purchaseData?.picture" class="avatar" alt="" />
      </div>
    </el-card>

    <div class="btn">
      <el-button @click="back">返回</el-button>
    </div>
  </div>
</template>

<script setup lang="ts">
import { ref } from "vue";
import { useRoute, useRouter } from "vue-router";
import { purchaseFoods, purchaseGet } from "@/api/logistics/purchase/purchase";
import { purchaseListData } from "@/api/logistics/purchase/type";
import dayjs from "dayjs";

const router = useRouter();
const route = useRoute();

// 图片根路径
const imgUrl = import.meta.env.VITE_IMG_URL;

const id: number = route.params.id as unknown as number;

// 获取表格信息
const TableData = ref<purchaseListData[]>([]);

const getListData = async () => {
  let res = await purchaseFoods(id);
  TableData.value = res.list;
};

// 获取采购信息
const purchaseData = ref<purchaseListData>();
const getData = async () => {
  let res = await purchaseGet(id);
  purchaseData.value = res;
};

// 返回
const back = () => {
  router.push("/diet/purchase");
};

onMounted(() => {
  getData();
  getListData();
});
</script>

<style lang="less" scoped>
.top {
  display: flex;
  justify-content: space-between;
  margin-bottom: 10px;

  .left {
    .box {
      display: flex;
      margin-bottom: 5px;

      .text {
        width: 200px;
        font-size: 14px;
      }

      .rgt {
        font-size: 14px;
      }
    }
  }

  .deliver {
    font-size: 32px;
    margin: 20px;
  }
}

.end {
  margin-top: 30px;

  .txt {
    margin-bottom: 10px;
  }
}

.avatar {
  width: 80px;
  height: 80px;
}

.btn {
  display: flex;
  justify-content: center;
  margin: 30px 0;
}
</style>
